<template>
  <div class="aa-pop">
    <div class="fg-carInfoBox" id="fg-carInfoBox" v-if="carInfoData != null">
      <div class="fg-carInfoBox-view">
        <div class="dtbox">
          <img :src="carInfoData.autoBrandLogo" alt="">
        </div>
        <div class="ddbox">
          <div class="gs-carInfoBox">{{ auto_text }}</div>
          <div class="vinCoda">
            <span>{{ vin_text }}</span>
          </div>
        </div>
      </div>
    </div>

    <FrequencyLimitPayment v-if="needPurchaseStatus == 1" :imUserCode="cangpei_param_ucd" @paySuccess="paySuccess" :imConsultantCode="cangpei_param_ccd" :set_price="PurchaseShopVipObj.set_price">
    </FrequencyLimitPayment>

    <div v-if="needPurchaseStatus == -1" class="aa-popBox">
      <div class="aa-popCenter">
        <div class="fg-carDetails">
          <div style="width: 100%; height: calc(100vh - 2.458rem);">
            <div class="hl-carDetailsBox">
              <div class="hl-carParameter">
                <div class="hl-singleParameterBox" v-for="(item, index) in autoDetails" :key="index">
                  <div class="hl-title">
                    <div class="hl-titleDecoration"></div>
                    <span>{{ item.GroupName }}</span>
                  </div>
                  <div class="hl-parameter">
                    <div class="hl-parameterLi" v-for="(ele, idx) in item.AutoParamList" :key="idx">
                      <span class="hl-parameterName">{{ ele.ParamName }}</span>
                      <span class="hl-parameterValue">{{ ele.ParamValue }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
import { mapState, mapGetters } from "vuex";
import FrequencyLimitPayment from '@/components/FrequencyLimitPayment';
export default {
  name: '',
  data() {
    return {
      param_vin: this.$com_util.getQueryString("vin"), //VIN码
      param_subid: this.$com_util.getQueryString("subid"), //VIN码
      carInfoData: null, //车型信息
      autoDetails: [], //车型详情
      auto_text: "", //车型展示文案
      vin_text: "", //VIN码展示文案

      needPurchaseStatus: 0,
      PurchaseShopVipObj: {
        needPurchase: false, // 是否需要购买云店VIP
        imConsultantName: "", // 客服名称
        set_price: "" // 查询费
      },
      cachekey: ""
    }
  },
  components: {
    FrequencyLimitPayment
  },
  computed: {
    ...mapGetters([
      "cangpei_param_gcd",
      "cangpei_param_ccd",
      "cangpei_param_ucd",
    ])
  },
  created() {
    if (this.cangpei_param_ccd) {
      this.NeedPurchaseShopVip();
    } else {
      this.needPurchaseStatus = -1;
    }
    this.initComponent();
  },
  methods: {
    // 构造分享代付云店VIP的缓存
    async BuildReplacePayShopVipCache() {
      const res = await this.$imServive({
        url: "/IMUser/BuildReplacePayShopVipCache",
        data: {
          imConsultantCode: this.cangpei_param_ccd
        },
      });
      this.cachekey = res.cachekey;
    },
    // 是否需要购买云店VIP
    async NeedPurchaseShopVip() {
      const res = await this.$imServive({
        url: "/IMUser/NeedPurchaseShopVip",
        data: {
          imConsultantCode: this.cangpei_param_ccd
        },
      });
      this.PurchaseShopVipObj.needPurchase = res.needPurchase;
      this.PurchaseShopVipObj.imConsultantName = res.imConsultantName;
      this.PurchaseShopVipObj.set_price = res.set_price;

      if (this.PurchaseShopVipObj.needPurchase) {
        this.needPurchaseStatus = 1;
        this.BuildReplacePayShopVipCache();
      } else {
        this.needPurchaseStatus = -1;
      }
    },
    paySuccess() {
      this.NeedPurchaseShopVip();
    },
    initComponent() {
      this.getVinParamByVin(); //获取车型信息列表
    },
    // 获取车型详情
    async getAutoInfoByVin() {
      const res = await this.$imServive({
        url: "/Auto/GetAutoInfoByVin",
        isShowLoading: true,
        data: {
          vinCode: this.param_vin,
          autoSubId: this.param_subid
        }
      });
      this.autoDetails = res.AutoParamGroups || [];
    },
    //获取精友参数
    async getVinParamByVin() {
      const res = await this.$imServive({
        url: "/Auto/GetJYAutoByVin",
        data: {
          vinCode: this.param_vin,
          autoSubId: this.param_subid
        },
      });

      if (res.length > 0) {
        this.carInfoData = res[0].VinAutoBase;
        this.getAutoInfoByVin(); //获取车型详情
        this.auto_text = this.build_autoText();
        this.vin_text = this.build_vinText();
      }
    },
    //VIN码文案
    build_vinText() {
      return this.param_vin;
    },
    //车型文案
    build_autoText() {
      if (this.param_vin.length > 0) {
        //VIN码请求模式
        if (this.carInfoData) {
          return (
            this.carInfoData.autoBrandName +
            " " +
            this.carInfoData.autoModelName
          );
        } else {
          return "";
        }
      } else {
        //车型请求模式
        if (this.carInfoData) {
          return (
            this.carInfoData.autoBrandName +
            " " +
            this.carInfoData.autoModelName +
            " " +
            this.carInfoData.autoModelSubName
          );
        } else {
          return "";
        }
      }
    }
  }
}
</script>

<style scpoed>
/* 弹层通用样式 */
.aa-pop {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: #fff;
}
/* 顶部一层车型logo */
.fg-carInfoBox {
  padding: 0.32rem;
  width: 100%;
  background: #fff;
  box-sizing: border-box;
}
.fg-carInfoBox-view {
  width: auto;
  height: 1.28rem;
  padding: 0.26666666666666666rem 0.28rem;
  background: #f6f6f6;
  display: flex;
  align-items: center;
}
.fg-carInfoBox-view .dtbox {
  width: 1.0666666666666667rem;
  height: 1.0666666666666667rem;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
}
.fg-carInfoBox .dtbox img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
.fg-carInfoBox .ddbox {
  height: 100%;
  margin-left: 0.24rem;
  flex: 1;
}
.fg-carInfoBox .ddbox .gs-carInfoBox {
  width: 100%;
  height: auto;
  font-size: 0.36rem;
  line-height: 0.64rem;
  color: #282828;
}
.fg-carInfoBox .ddbox .vinCoda {
  width: auto;
  font-size: 0.32rem;
  color: #666;
  display: flex;
  align-items: center;
}
.fg-carInfoBox .ddbox .vinCoda > span {
  font-size: 0.32rem;
  font-weight: normal;
  text-align: left;
  color: #666;
}
/* 顶部一层车型logo */
.aa-popBox {
  width: 100%;
  height: calc(100vh - 2.46rem);
  overflow: hidden;
  box-sizing: border-box;
}
.aa-popCenter {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}
/*车型详情弹层*/
.fg-carDetails {
  width: 100%;
  height: auto;
  background: #fff;
  overflow-x: hidden;
  overflow-y: auto;
  border: 2px solid #eee;
}
/*车型详情浮层*/
.hl-carDetailsBox {
  width: 100%;
  height: auto;
  background: #edf1f6;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}
.hl-carParameter {
  width: 92%;
  padding-bottom: 0.4rem;
}
.hl-singleParameterBox {
  width: 100%;
  height: auto;
  margin-top: 0.4rem;
  background: #fff;
  border-radius: 0.21333333333333335rem;
  overflow: hidden;
  box-shadow: 0 0 0.21333333333333335rem rgba(0, 0, 0, 0.1);
}
.hl-title {
  width: 100%;
  height: 1.12rem;
  background: #f6f6f6;
  padding: 0 0.4rem;
  box-sizing: border-box;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  position: relative;
  z-index: 2;
}
.hl-titleDecoration {
  width: 0.08rem;
  height: 0.4rem;
  border-radius: 0.04rem;
  background: #e74c3c;
  margin-right: 0.24rem;
  display: block;
}
.hl-title span {
  width: auto;
  height: auto;
  font-size: 0.4rem;
  line-height: 0.56rem;
  text-align: left;
  color: #666;
}
.hl-parameter {
  width: 100%;
  height: auto;
  padding: 0 0.4rem;
  margin-top: -0.013333333333333334rem;
}
.hl-parameterLi {
  width: 100%;
  height: auto;
  padding: 0.16rem 0;
  border-top: 0.013333333333333334rem solid #d8d8d8;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.hl-parameterName {
  width: 3.44rem;
  font-size: 0.37333333333333335rem;
  line-height: 0.72rem;
  text-align: left;
  color: #8e8e8e;
  flex-shrink: 0;
}
.hl-parameterValue {
  width: 100%;
  font-size: 0.37333333333333335rem;
  line-height: 0.72rem;
  text-align: left;
  color: #181818;
  flex-shrink: 0;
}
.hl-carDetailsClose {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 2.24rem;
  padding-top: 0.64rem;
  background-image: linear-gradient(
    to top,
    rgba(237, 241, 246, 1) 0%,
    rgba(237, 241, 246, 1) 50%,
    rgba(237, 241, 246, 0) 100%
  );
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 5;
}
.hl-carDetailsClose button {
  width: 1.84rem;
  height: 0.8rem;
  background: #fff;
  border: 1px solid #377de8;
  border-radius: 0.4rem;
  font-size: 0.37333333333333335rem;
  line-height: 0.64rem;
  text-align: center;
  color: #377de8;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
